package com.scfire.content

import grails.converters.JSON
import com.scfire.baseInfo.Gson
import com.scfire.project.*
import com.scfire.security.Member
import com.scfire.weixin.*
import javax.servlet.http.HttpServletResponse
import com.scfire.util.*;
import org.apache.commons.logging.*;

class ArticlePcController {
	
	def springSecurityService
	def authenticationTrustResolver
	
	def deviceInfoService
	def weiXinService
	
	String oauthCallBack = WeiXinConstants.oauth_pc_url+"?appid="+WeiXinConstants.appid_pc+"&redirect_uri="+URLEncoder.encode(WeiXinConstants.login_url+"?type=微信PC端")+"&response_type=code&scope=snsapi_login&state=STATE&#wechat_redirect"
	
	def LOG = LogFactory.getLog(ArticlePcController.class)

    	/**
	 * show Article Pc
	 */
	def showArticle(Articlepc articlepcInstance){
		def format = request.getHeader("format")
		def userAgent = request.getHeader("User-Agent")
		def str = deviceInfoService.getDeviceInfo(userAgent)
		//获取用户基本信息
		def user = (Member)springSecurityService.getCurrentUser()
		def roles = springSecurityService.getAuthentication()?.authorities
		
		def article
		try {
			article = Articlepc.findById(Integer.parseInt(params.articleid))
		} catch (Exception e) {
			e.printStackTrace();
			notFound();
		}
		
		render view: "showArticle", model:[article:article, user:user]
	}
	
	protected void notFound() {
		def gson = new Gson()
		withFormat {
			html {
				flash.message = "未找到该项目！"
				redirect (controller: "errors", action: "notFound")
			}
			json {
				gson.setResult(false)
				gson.setCode(404)
				gson.setInfo(["text": "未找到该项目！"])
				render gson as JSON
			}
		}
	}
}
